<template>
  <div>
    <img src="./static/image/bg-login.jpg" class="login-img1">
    <div class="login-logo">
      <img src="./static/image/user.jpg" class="login-img">
    </div>
    <div class="login-title">
      <h2>欢迎体验study4j学习框架</h2>
    </div>
    <div class="login-img4">
      <el-form
        ref="loginForm"
        label-position="left"
        :model="loginForm"
        label-width="40px"
      >
        <el-form-item
          :rules="[{ required: true, message: '用户名不能为空',trigger: 'blur'}]"
          prop="userNo"
          class="login-from"
        >
          <el-input v-model="loginForm.userNo" maxlength="30" type="text" prefix-icon="el-icon-user" class="login-input" placeholder="用户账号" />
        </el-form-item>
        <el-form-item
          :rules="[{ required: true, message: '密码不能为空',trigger: 'blur'}]"
          prop="password"
          class="login-from"
        >
          <el-input
            v-model="loginForm.password"
            type="password"
            maxlength="30"
            prefix-icon="el-icon-key"
            class="login-input"
            placeholder="密码"
          />
        </el-form-item>
        <el-form-item class="login-btn">
          <el-button
            :loading="loginLoading"
            type="primary"
            style="width:280px;"
            round
            @click="login()"
          >
            登录
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="login-bottom">
      <p>
        <a
          href="http://www.beian.miit.gov.cn"
          target="view_window"
          style="color:#fff;"
        >湘ICP备18022860号</a>
      </p>
    </div>
  </div>
</template>

<script>
import { setToken } from '@/utils/auth'
export default {
  data() {
    return {
      loginLoading: false,
      loginForm: {
        userNo: 'admin',
        password: '123456'
      }
    }
  },
  created() {

  },
  methods: {
    login() {
      this.$refs['loginForm'].validate(valid => {
        if (valid) {
          this.loginLoading = true
          this.httpRequest({
            url: '/sys/login',
            method: 'post',
            data: this.loginForm
          }).then((response) => {
            console.log(JSON.stringify(response))
            setToken(response.data)
            this.$router.push({ path: this.redirect || '/' })
          }).catch(() => {
            this.loginLoading = false
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style>
.login-bottom {
  position: fixed;
  width: 100%;
  bottom: 5%;
  text-align: center;
}
.login-title {
  position: fixed;
  width: 100%;
  text-align: center;
  margin-top: 180px;
}
.login-img {
  border-radius: 45px;
  width: 90px;
}
.login-logo {
  position: fixed;
  width: 100%;
  text-align: center;
  margin-top: 90px;
}
.login-img1 {
  width: 100%;
  position: fixed;
}
.login-img4 {
  width: 360px;
  height: 250px;
  background: #fff;
  border-radius: 7px;
  position: fixed;
  left: 50%;
  right: 50%;
  transform: translateX(-50%);
  margin-top: 250px;
}
.login-from {
  width: 240px;
  margin-top: 30px;
}
.login-input {
  width: 280px;
}
.login-btn {
  margin-top: 30px;
}
</style>
